
<?
	 layout("/inc/win_layout.html",{title:sysTitle}){
    ?>

<div class="row" style="min-height: auto;padding-bottom: 20px;">
<input id="knowledgeId" type="hidden" class="form-control" />
<input id="id" type="hidden" class="form-control" />
	<div class="col-lg-12">
		<div class="panel ">
			<div class="panel-body pan">
				<div class="form-body pal" style="width:auto; height: auto">
					<div style="width:400px; margin:0 30px 0 80px; padding-bottom: 15px;">
						<label class="col-md-3 control-label">中文名称
							<span class='require'>*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<input id="nameZh" type="text" name="nameZh" class="form-control" onchange="pinYin(this.value)"  />
							</div>
						</div>
					</div>
					<div style="width:400px; margin:0 30px 0 80px; padding-bottom: 15px;">
						<label class="col-md-3 control-label">英文名称
							<span class='require'>*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<input id="nameEn" type="text" class="form-control" />
							</div>
						</div>
					</div>
					<div style="width:400px; margin:0 30px 0 80px; padding-bottom: 15px;">
						<label class="col-md-3 control-label">父节点
							<span class='require'>*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<select id="parentId" class="form-control">
									<option value="0">无</option>
								<?for(communityKnowledgePoint in communityKnowledgePointList){?>
									<option value="${communityKnowledgePoint.id}">${communityKnowledgePoint.nameZh}</option>
								<?}?>
							</select>
							</div>
						</div>
					</div>
					<div style="width:400px; margin:0 30px 0 80px; padding-bottom: 15px;">
						<label class="col-md-3 control-label">状态
							<span class='require'>*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<select id="status" class="form-control">
								<option value="0">正常</option>
								<option value="1">禁用</option>
							</select>
							</div>
						</div>
					</div>
					<div style="width:400px; margin:0 30px 0 80px; padding-bottom: 15px;">
						<label class="col-md-3 control-label">描述</label>
						<div class="col-md-9">
							<div class="input-icon">
								<textarea id="description"  rows="3" cols="20" class="form-control" ></textarea> 
							</div>
						</div>
					</div>
					<div style="width:400px; margin:0 30px 0 80px; padding-bottom: 15px;">
						<label class="col-md-3 control-label">排序
							<span class='require'>*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<input id="sort" type="text" class="form-control"/>
							</div>
						</div>
					</div>
				</div>	
			</div>
		</div>
	</div>
</div>

<?} ?>
<script type="text/javascript">
	function getQueryString(name) { 
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
		var r = window.location.search.substr(1).match(reg); 
		if (r != null) return unescape(r[2]); return null; 
	} 
	var winName=getQueryString("winName");
	var addUploadType = window.parent.window[winName].getaddUploadType();
	var knowledgePointId = window.parent.window[winName].getknowledgePointId();
	var id = window.parent.window[winName].getId();
	$(function() {
		$("#knowledgeId").val(knowledgePointId);
		$("#id").val(id);
		if (addUploadType != 0) {
			demo();
		}
	});
	function Page() {
				if($.trim($("#nameZh").val()).length<1) {
    	        	alert('中文名称不能为空！');
    	        	return null;
    	        }
    	        if($.trim($("#nameEn").val()).length<1) {
    	        	alert('英文名称不能为空！');
    	        	return null;
    	        }
    	        if($.trim($("#sort").val()).length<1) {
    	        	alert('排序不能为空！');
    	        	return null;
    	        }
    	        if(isNaN($("#sort").val())){
                  alert("必须是数字");
                  return null;
                  }
		$.ajax({
			type : "post",
			url : "addOrUploadCommunityKnowledgePoint.do",
			data : {
				"id" : $("#id").val(),
				"knowledgeId":$("#knowledgeId").val(),
				"nameZh" : $("#nameZh").val(),
				"nameEn" : $("#nameEn").val(),
				"parentId" : $("#parentId").val(),
				"status" : $("#status").val(),
				"description" : $("#description").val(),
				"sort": $("#sort").val(),
			},
			dataType : "json",
			async : false,
			success : function(data) {
				var index = parent.layer.getFrameIndex(window.name);
				if(data[0].data == 'yes'){
					parent.layer.msg('提交成功！');
					window.parent.window[winName].initTree();
					window.parent.layer.close(index);
				}else{
					parent.layer.msg('提交失败！');
				}
			},
			error : function(data) {
				alert("请求失败");
				
			}
		});
	}
	function demo() {
		$.getJSON('findCommunityKnowledgePoint.do', {
			id : $("#id").val()
		//向服务端传的参数，此处只是演示
		}, function(res) {
			//此处仅仅是为了演示变化的内容
			$("#nameZh").val(res[0].nameZh);
			$("#nameEn").val(res[0].nameEn);
			$("#description").val(res[0].description);
			$("#sort").val(res[0].sort);
			$("#id").val(res[0].id);
			$("#knowledgeId").val(res[0].knowledgeId);
			$("#parentId").val(res[0].parentId);
			$("#status").val(res[0].status);
		});
	};

	//汉字转拼音
  function pinYin(pinyinName){
		$.ajax({
			type : "post",
			url : "pinYin.do",
			data : {
				"pinYin" : pinyinName,
			},
			async : false,
			dataType : "json",
			success : function(data) {
				if(data[0].length > 32){
					layer.msg('自动转换英文名长度过长!请手动输入！');
					$("#nameEn").val("");
				}else{
					$("#nameEn").val(data);
				}
			},
			error : function(data) {
				alert("请求失败");
			}
		})
	}
</script>


